<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en" xmlns:th="https://www.thymeleaf.org">
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link th:href="@{/css/shop.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/css/Sellerber.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/css/bkg_ui.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/font/css/font-awesome.min.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/js/jquery-1.9.1.min.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/js/Validform/Validform.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.cookie.js}"></script>
    <script th:src="@{/js/shopFrame.js}" type="text/javascript"></script>
    <script th:src="@{/js/Sellerber.js}" type="text/javascript"></script>
    <script th:src="@{/js/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <script th:src="@{/js/administrator_list.js}" type="text/javascript"></script>
    <title>管理员列表</title>
</head>
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<script src="js/css3-mediaqueries.js" type="text/javascript"></script>
<![endif]-->
<body>
<input type="hidden" id="adminlevel" th:value="${session.admin.level}"/>
<div class="margin Competence_style" id="page_style">
    <div class="operation clearfix">
        <form id="pageFrm" th:action="@{/admin/getAdministrator_list}" method="post">
            <button class="btn button_btn btn-danger" type="button" onclick=""><i class="fa fa-trash-o"></i>&nbsp;删除
            </button>
            <a href="javascript:void(0)" id="administrator_add" shiro:hasPermission="user:addAdmin" class="btn button_btn bg-deep-blue"><i
                    class="fa  fa-edit"></i>&nbsp;添加管理员</a>
            <select class="select Competence_sort" name="admin-role" size="1" id="Competence_sort" th:attr="_value=${level}">
                <option  value="-1">--选择分类--</option>
                <option  value="0">超级管理员</option>
                <option  value="1">省级代理商</option>
                <option  value="2">市级代理商</option>
                <option  value="3">区县代理商</option>
            </select>
            <div class="search  clearfix">

                <input name="area" id="area" th:value="${area==null?'':area}" type="text" class="form-control col-xs-8"/>
                <button class="btn button_btn bg-deep-blue " onclick="page_nav(document.forms[0],this)" type="button" id="selArea">
                    <i class="fa  fa-search"></i>&nbsp;搜索
                </button>
            </div>
        </form>
    </div>
    <div class="compete_list">
        <table id="sample_table" class="table table_list table_striped table-bordered dataTable no-footer">
            <thead>
            <tr>
                <th class="center" width="50px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                <th width="80px">账号</th>
                <th width="130px">角色</th>
                <!--<th width="100px">父级编号</th>-->
                <th width="200px">地区标注</th>
                <th width="110px">支付宝账号</th>
                <th width="110px">微信账号</th>
                <th class="hidden-480" width="180px">加入时间</th>
                <th class="hidden-480" width="180px">到期时间</th>
                <th class="hidden-480" width="120px">电话号码</th>
                <th class="hidden-480" width="250px">操作</th>
            </tr>
            </thead>
            <tbody id="tbody">
            <tr th:each="admin : ${page.content}">
                <td class="center"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                <td th:text="${admin.account}"></td>
				<td th:text=" ${admin.level==0?'超级管理员':admin.level==1?'省级代理商':admin.level==2?'市级代理商':admin.level==3?'区县代理商':'数据损毁'}"></td>
                <td th:text="${admin.area}"></td>
                  <td th:text="${admin.alipay}"></td>
                <td th:text="${admin.weChat}"></td>
                  <td th:text="${#dates.format(admin.enterTime,'yyyy-MM-dd hh:mm:ss')}"></td>
                <td th:text="${#dates.format(admin.dueTime,'yyyy-MM-dd hh:mm:ss')}"></td>
                  <td th:text="${admin.adminTel}"></td>
                <!--<td class="td-status"><span class="label label-success label-sm">已启用</span></td>-->
                <td class="td-manage">
                    <!--<a title="停用" onclick="Competence_close(this,'12')" href="javascript:;" class="btn button_btn btn-Dark-success">停用</a> -->
                    <a title="编辑"  th:onclick="'javascript:Competence_modify('+this+','+${admin.adminId}+')'" href="javascript:;"
                       class="btn button_btn bg-deep-blue updInfo" >编辑
                    </a>

                    <a title="删除" href="javascript:;"  shiro:hasPermission="user:deleteAdmin" th:onclick="'javascript:Competence_del('+this+','+${admin.adminId}+','+${admin.level}+')'"
                       class="btn button_btn btn-danger">删除</a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<div id="text1"></div>
<input type="hidden" id="totalElements" th:value="${page.totalElements}"/>
<input type="hidden" id="number" th:value="${page.number}"/>
<input type="hidden" id="level11" th:value="${level}"/>
<!--添加管理员-->
<div id="add_administrator" class=" add_administrator" style="display:none">
    <div class="add_style add_administrator_style">
        <form id="form-admin-add">
            <ul>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i>*</i>用户名：</label>
                    <div class="formControls col-xs-6">
                        <input type="text" class="input-text col-xs-12" value="" placeholder="" id="account"
                               name="account"></div>
                    <div class="col-4"><span class="accountText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i class="c-red">*</i>初始密码：</label>
                    <div class="formControls col-xs-6">
                        <input type="password" placeholder="密码" name="adminPwd" id="adminPwd"
                               class="input-text col-xs-12">
                    </div>
                    <div class="col-4"><span class="adminPwdText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i class="c-red">*</i>确认密码：</label>
                    <div class="formControls  col-xs-6">
                        <input type="password" placeholder="确认新密码" id="adminPwd2" name="adminPwd2"
                               class="input-text col-xs-12">
                    </div>
                    <div class="col-4"><span class="adminPwd2Text"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i class="c-red">*</i>电话号码：</label>
                    <div class="formControls  col-xs-6">
                        <input type="text" placeholder="电话号码" id="adminTel" name="adminTel"
                               class="input-text col-xs-12">
                    </div>
                    <div class="col-4"><span class="adminTelText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i class="c-red">*</i>级&nbsp;别：</label>
                    <div class="formControls  skin-minimal col-xs-6" id="level">
                        <label><input name="form-field-radio" type="radio" name="radio" value="1" class="ace"
                                      checked="checked"><span class="lbl">省级代理商</span></label>&nbsp;&nbsp;
                        <label><input name="form-field-radio" type="radio" name="radio" value="2" class="ace"><span
                                class="lbl">市级代理商</span></label>&nbsp;&nbsp;
                        <label><input name="form-field-radio" type="radio" name="radio" value="3" class="ace"><span
                                class="lbl">区县代理商</span></label>
                    </div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-2 col-lg-2"><i class="c-red">*</i>入驻时间：</label>
                    <div class="formControls col-xs-6">
                        <input type="text" class="input-text col-xs-12" name="enterTime" id="enterTime"
                               disabled="disabled">
                    </div>
                </li>
                <li class="clearfix col-xs-12 col-lg-12 align">
                    <input class="btn button_btn bg-deep-blue btn_height" type="button" id="Add_Administrator1"
                           value="提交注册">
                    <input name="reset" type="reset" id="reset" class="btn button_btn btn-infobtn-gray btn_height" value="取消重置"/>
                </li>
            </ul>
        </form>
    </div>
</div>

<!--修改代理商-->
<input type="hidden" class="hidden_adminId_upd" id="aaaaaa">
<div id="upd_administrator" class=" add_administrator" style="display:none">
    <div class="add_style add_administrator_style" style="padding: 0 0 0 10px;">
        <form id="form-admin-upd">
            <ul>
                <li class="clearfix">
                    <label class="label_name col-xs-3 col-lg-2"><i>*</i>地区标注：</label>
                    <div class="formControls col-xs-6">
                        <input type="text" class="input-text col-xs-12" value="" placeholder="" id="upd_area"
                               name="upd_area" th:onblur="'javascript:blur_area('+this+')'"></div>
                    <div class="col-4"><span class="upd_areaText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-3 col-lg-2" style="width: 18%"><i>*</i>支付宝账号：</label>
                    <div class="formControls col-xs-6">
                        <input type="text" class="input-text col-xs-12" value="" placeholder="" id="upd_alipay"
                               name="upd_alipay" th:onblur="'javascript:blur_alipay('+this+')'" style="margin-left: -8px"></div>
                    <div class="col-4"><span class="upd_alipayText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-3 col-lg-2"><i>*</i>微信账号：</label>
                    <div class="formControls col-xs-6">
                        <input type="text" class="input-text col-xs-12" value="" placeholder="" id="upd_weChat"
                               name="upd_weChat" th:onblur="'javascript:blur_weChat('+this+')'"></div>
                    <div class="col-4"><span class="upd_weChatText"></span></div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-3 col-lg-2"><i class="c-red">*</i>电话号码：</label>
                    <div class="formControls  col-xs-6">
                        <input type="text" placeholder="电话号码" id="upd_adminTel" name="upd_adminTel"
                               class="input-text col-xs-12" th:onblur="'javascript:blur_adminTel('+this+')'">
                    </div>
                    <div class="col-4"><span class="upd_adminTelText"></span></div>
                </li>

                <li class="clearfix col-xs-12 col-lg-12 align">
                    <input class="btn button_btn bg-deep-blue btn_height" type="button" id="UPD_Administrator1"
                           value="提交修改">
                    <input name="reset" type="reset" class="btn button_btn btn-infobtn-gray btn_height" value="取消重置"/>
                </li>
            </ul>
        </form>
    </div>
</div>
</body>
</html>
<script>
    /*添加管理员*/
    $('#administrator_add').on('click', function () {
        layer.open({
            type: 1,
            title: '添加信息',
            area: ['600px', ''],
            shadeClose: false,
            content: $('#add_administrator'),

        });
    })


    function page_nav(frm, obj) {
        frm.submit();
    };

    $("#Competence_sort").bind("change", function () {
        var v = $("#Competence_sort option:selected").val();
        var area = $("#area").val();
        location.href = "/admin/getAdministrator_list?level=" + v + "&area="+area+"";
    })



    function blur_area(thi){
        var area = $(thi).val();
        if (area == null | area == "") {
            $(".upd_areaText").html("  地区标注不能为空");
            return;
        }
        $(".accountText").html("");
    }
    function blur_alipay(thi){
        var alipay = $(thi).val();
        if (alipay == null | alipay == "") {
            $(".upd_alipayText").html("  支付宝账号不能为空");
            return;
        }
        $(".accountText").html("");
    }
    function blur_weChat(thi){
        var weChat = $(thi).val();
        if (weChat == null | weChat == "") {
            $(".upd_weChatText").html("  微信账号不能为空");
            return;
        }
        $(".accountText").html("");
    }
    function blur_adminTel(thi){
        var adminTel = $(thi).val();
        if (adminTel == null | adminTel == "") {
            $(".upd_adminTelText").html("  电话号码能为空");
            return;
        }
        if(!(/^1[3456789]\d{9}$/.test(adminTel))){
            $(".upd_adminTelText").html("手机号码有误，请重填");
            return;
        }
        $(".accountText").html("");
    }

    function Competence_modify(frm,obj){
        $("#aaaaaa").val(obj);
        /*修改管理员*/
            layer.open({
                type: 1,
                title: '修改信息',
                area: ['600px', ''],
                shadeClose: false,
                content: $('#upd_administrator'),

            });
        $.ajax({
            url:"/admin/findAdminByAdminId",
            method: "POST",
            data: {
                adminId: obj,
            },
            dataType: "json",
            success: function (data) {
                $.each(data.content, function (i, v) {
                    $("#upd_area").val(v.area);
                    $("#upd_alipay").val(v.alipay);
                    $("#upd_weChat").val(v.weChat);
                    $("#upd_adminTel").val(v.adminTel);
                })
            }
        })
    }

    $("#UPD_Administrator1").click(function () {
        var upd_area=$("#upd_area").val();
        var upd_alipay=$("#upd_alipay").val();
        var upd_weChat=$("#upd_weChat").val();
        var upd_adminTel=$("#upd_adminTel").val();
        if(upd_area=="" | upd_area==null){
            $(".upd_areaText").html("地区标注不能为空");
            return;
        }
        $(".upd_areaText").html("");
        $(".upd_areaText").html("");
        if(upd_alipay=="" | upd_alipay==null){
            $(".upd_alipayText").html("支付宝账号不能为空");
            return;
        }
        $(".upd_alipayText").html("");
        $(".upd_alipayText").html("");
        if(upd_weChat=="" | upd_weChat==null){
            $(".upd_weChatText").html("微信账号不能为空");
            return;
        }
        $(".upd_weChatText").html("");
        $(".upd_weChatText").html("");
        if(upd_adminTel=="" | upd_adminTel==null){
            $(".upd_adminTelText").html("电话号码不能为空");
            return;
        }
        $(".upd_adminTelText").html("");
        if(!(/^1[3456789]\d{9}$/.test(upd_adminTel))){
            $(".upd_adminTelText").html("手机号码有误，请重填");
            return;
        }
        $(".upd_adminTelText").html("");

        var adminId= $("#aaaaaa").val();
        $.ajax({
            url:"/admin/updateinfo",
            method: "POST",
            data: {
                adminId: adminId,
                area:upd_area,
                alipay:upd_alipay,
                weChat:upd_weChat,
                adminTel:upd_adminTel,
            },
            dataType: "text",
            success: function (data) {
                if(data>0){
                    layer.msg('修改成功');
                    var avar=window.setTimeout(function () {
                        location.href = "/admin/getAdministrator_list";
                        window.clearTimeout(avar)
                    },1000);

                }else{
                    layer.msg('修改失败');
                }
            }
        })
    })

    /**
     * 删除
     */
    function Competence_del(frm,obj,lev){
        layer.msg('确定要删除该代理商吗？？？', {
            time: 10000 //不自动关闭
                ,btn: ['确定', '取消']
            ,yes: function(index){
                var adminId = obj;
                var level=lev;
                $.ajax({
                    url:"/admin/delAdmin",
                    method: "POST",
                    data: {
                        adminId: adminId,
                        level:level,
                    },
                    dataType: "text",
                    success: function (data) {
                        if (data == 1) {
                            layer.msg('删除成功');
                            var v = $("#Competence_sort option:selected").val();
                            var area = $("#area").val();
                            var avar=window.setTimeout(function () {
                                location.href = "/admin/getAdministrator_list?level=" + v + "&area="+area+"";
                                window.clearTimeout(avar)
                            },1000);

                        } else if(data==0){
                            layer.msg('删除失败，该下面代理商不能删除');
                        } else {
                            layer.msg('删除失败');
                        }
                    }
                })
            }
        });
    }

    /**
     * 添加
     */
    function Competence_add() {
        var account=$("#account").val();
        var adminPwd=$("#adminPwd").val();
        var adminPwd2=$("#adminPwd2").val();
        var adminTel=$("#adminTel").val();
        $("#account").blur(function () {
            account = $("#account").val();
            if (account == null | account == "") {
                $(".accountText").html("用户名不能为空");
                return;
            }
            $(".accountText").html("");
        })
        $("#adminPwd").blur(function () {
            adminPwd = $("#adminPwd").val();
            if (adminPwd == null | adminPwd == "") {
                $(".adminPwdText").html("初始密码不能为空");
                return;
            }
            $(".adminPwdText").html("");
        })
        $("#adminPwd2").blur(function () {
            adminPwd2 = $("#adminPwd2").val();
            if (adminPwd2 == null | adminPwd2 == "") {
                $(".adminPwd2Text").html("确认密码不能为空");
                return;
            }
            if (adminPwd != adminPwd2) {
                $(".adminPwd2Text").html("两次密码不一致");
                return;
            }
            $(".adminPwd2Text").html("");
        })
        $("#adminTel").blur(function () {
            adminTel = $("#adminTel").val();
            if (adminTel == null | adminTel == "") {
                $(".adminTelText").html("电话号码不能为空");
                return;
            }
            if(!(/^1[3456789]\d{9}$/.test(adminTel))){
                $(".adminTelText").html("手机号码有误，请重填");
                return;
            }
            $(".adminTelText").html("");
        })

        /**
         * 提交注册
         */
        $("#Add_Administrator1").click(function () {
           account=$("#account").val();
           adminPwd=$("#adminPwd").val();
           adminPwd2=$("#adminPwd2").val();
           adminTel=$("#adminTel").val();
            if (account == null | account == "") {
                $(".accountText").html("用户名不能为空");
                return;
            }
            if (adminPwd == null | adminPwd == "") {
                $(".adminPwdText").html("初始密码不能为空");
                return;
            }
            if (adminPwd2 == null | adminPwd2 == "") {
                $(".adminPwdText2").html("确认密码不能为空");
                return;
            }
            if (adminPwd2 != adminPwd) {
                $(".adminPwdText2").html("两次密码不一致");
                return;
            }
            if (adminTel == null | adminTel == "") {
                $(".adminTelText").html("电话号码不能为空");
                return;
            }
            if(!(/^1[3456789]\d{9}$/.test(adminTel))){
                $(".adminTelText").html("手机号码有误，请重填");
                return;
            }
            $.ajax({
                url: "/admin/findAdminByAccount",
                method: "POST",
                data: {
                    account: account,
                },
                dataType: "json",
                success: function (data) {
                    if (data.totalElements == 0) {
                        var level = $("#getLevel").val();
                        var fLevel = $("#adminlevel").val();
                        var enterTime = $("#enterTime").val();
                        var reg = new RegExp("/", "g");//g,表示全部替换。
                        enterTime.replace("/", "-");
                        $.ajax({
                            url: "/admin/addAdmin",
                            method: "POST",
                            data: {
                                account: account,
                                adminPwd: adminPwd,
                                adminTel: adminTel,
                                level: level,
                                fatherId:fLevel,
                                enterTime: enterTime,
                            },
                            dataType: "text",
                            success: function (data) {
                                if (data > 0) {
                                    layer.msg('注册成功');
                                    var avar=window.setTimeout(function () {
                                        location.href = "/admin/getAdministrator_list";
                                        window.clearTimeout(avar)
                                    },1000);

                                } else {
                                    layer.msg('注册失败');
                                }
                            }
                        })
                    } else {
                        alert("账号已存在,请重新填写");
                    }
                }
            })
        })
    }


    $(function () {
        //绑定时间
        Competence_add();
        var level=$("#adminlevel").val();
        //绑定级别
        if(level!=null && level!=""){
            $("#level").html("");
            if(level==0){
                $("#level").append("<label><input name='form-field-radio' id='getLevel' type='radio' name='radio' value='1' class='ace' checked='checked'><span class='lbl'>省级代理商</span></label>&nbsp;&nbsp;");
            }
            if(level==1){
                $("#level").append("<label><input name='form-field-radio' id='getLevel' type='radio' name='radio' value='2' class='ace' checked='checked'><span class='lbl'>市级代理商</span></label>&nbsp;&nbsp;");
            }
            if(level==2){
                $("#level").append("<label><input name='form-field-radio' id='getLevel' type='radio' name='radio' value='3' class='ace' checked='checked'><span class='lbl'>区县代理商</span></label>&nbsp;&nbsp;");
            }
        }
    })


        $("#administrator_add").click(function () {
            var myDate = new Date();
            myDate.getHours();       //获取当前小时数(0-23)
            myDate.getMinutes();     //获取当前分钟数(0-59)
            myDate.getSeconds();     //获取当前秒数(0-59)
            myDate.toLocaleDateString();     //获取当前日期
            $("#enterTime").val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1) + "-" + myDate.getDate() + "  " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds());
        })





//             //****复选框选中******
//          $('table th input:checkbox').on('click', function () {
//              var that = this;
//              $(this).closest('table').find('tr > td:first-child input:checkbox')
//                  .each(function () {
//                      this.checked = that.checked;
//                      $(this).closest('tr').toggleClass('selected');
//                  });
//
//          });
//
//
// //字数限制
//         function checkLength(which) {
//             var maxChars = 100; //
//             if (which.value.length > maxChars) {
//                 layer.open({
//                     icon: 2,
//                     title: '提示框',
//                     content: '您输入的字数超过限制!',
//                 });
//                 // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
//                 which.value = which.value.substring(0, maxChars);
//                 return false;
//             } else {
//                 var curr = maxChars - which.value.length; //250 减去 当前输入的
//                 document.getElementById("sy").innerHTML = curr.toString();
//                 return true;
//             }
//         }

</script>
